package com.boc.langxiang.ui.activity.me;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.boc.langxiang.App;
import com.boc.langxiang.R;
import com.boc.langxiang.contract.common.AccountUpdateNickNameContract;
import com.boc.langxiang.entity.events.NickNameChangeEvent;
import com.boc.langxiang.manager.UserInfoManager;
import com.boc.langxiang.presenter.common.AccountUpdateNickNamePresenter;
import com.boc.langxiang.util.T;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SetModifyNickNameActivity extends MeBaseToolBarActivity implements AccountUpdateNickNameContract.View {


    @BindView(R.id.et_me_set_modifyname)
    EditText etMeSetModifyname;
    private AccountUpdateNickNamePresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_modify_nick_name);
        ButterKnife.bind(this);
        setToolBarTitle("修改昵称");
        mPresenter = new AccountUpdateNickNamePresenter(this);

    }


    @Override
    protected int setToolBarBackgroundColor() {
        return Color.WHITE;
    }

    @Override
    protected int setToolBarBackImg() {
        return R.drawable.icon_me_left;
    }

    @Override
    protected int setToolBarTitleColor() {
        return Color.BLACK;
    }

    @Override
    public void showLoading() {
        showProgressDialog();
    }

    @Override
    public void hideLoading() {
        hideDialog();
    }

    @Override
    public void onError(String code, String msg) {
        T.showShort(mContext, msg);
    }

    @OnClick({R.id.iv_me_set_delete, R.id.btn_me_set_commitname})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_me_set_delete:
                etMeSetModifyname.setText("");
                break;
            case R.id.btn_me_set_commitname:
                String nickName = etMeSetModifyname.getText().toString();
                if(TextUtils.isEmpty(nickName)){
                    Toast.makeText(App.getInstance(), "输入不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }

                if(nickName.equals(UserInfoManager.getInstance().getUserInfo().getNickname())){
                    Toast.makeText(App.getInstance(), "请输入不同的昵称", Toast.LENGTH_SHORT).show();
                    return;
                }

                mPresenter.accountUpdateNickName(nickName);
                break;
        }
    }


    @Override
    public void endActivity() {
        EventBus.getDefault().post(new NickNameChangeEvent());
        finish();
    }
}
